#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define MAXLINE 512

int main( int argc, char *argv[] )
{
	char name[L_tmpnam], line[MAXLINE];
	FILE *fp;

	cout << tmpnam( NULL ) << endl;

	tmpnam( name );
	cout << name << endl;

	if( ( fp = tmpfile() ) == NULL ) {
		perror( "can create tmpfile\n" );
		return -1;
	}
	fputs( "liubin tmpfile and tmpnam test", fp );
	rewind( fp ); //  same with fseek(fp, 0L, SEEK_SET)
	if( fgets( line, sizeof(line), fp ) == NULL ) {
		perror( "fgets error" );
		return -1;
	}

	cout << line;
	return 0;
}

// g++  提示：the use of 'tmpnam' is dangerous, better use 'mkstemp'
